package Test.Login_teacher.dao.impl;

import Test.Login_teacher.dao.UserDao;

import java.io.*;

/**
 * DAO的实现类
 * 类似MVC的model层+service业务层
 * 它即和数据库交互，也处理业务逻辑
 */
public class UserDaoImpl implements UserDao {
    //登录验证逻辑
    @Override
    public boolean login(String userName, String password) {
        boolean flag = false;
        //读取数据库中的账号密码
        try {
            BufferedReader bw = new BufferedReader(new FileReader("./src/main/java/Test/Test2/userInfo.txt"));
            //创建变量存储读取的变量
            String line = null;
            while ((line = bw.readLine()) != null){
                String[] str = line.split("=");
                if (str[0].equals(userName) && str[1].equals(password)){
                    flag = true;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return flag;
    }
}
